package com.xsq.control;

import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;

public class MediaOp {

	private Context mContext;

	


	public MediaOp(Context c) {
		mContext = c;

	}
	
	
	
	public void playSuccess(){
		try {
			AssetManager assetManager = mContext.getAssets();
			AssetFileDescriptor afd = assetManager.openFd("m1.mp3");
			
			
			final MediaPlayer	mPlayer  = new MediaPlayer();
			
			
			mPlayer.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength());
			mPlayer.setLooping(false);// 循环播放
			mPlayer.prepare();
			mPlayer.start();
			
			mPlayer.setOnCompletionListener(new OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mp) {
                	mPlayer.reset();
                	mPlayer.release();
                }
            });
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void playFail(){
		try {
			AssetManager assetManager = mContext.getAssets();
			AssetFileDescriptor afd = assetManager.openFd("m2.mp3");
			
			final MediaPlayer	mPlayer  = new MediaPlayer();
			mPlayer.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength());
			mPlayer.setLooping(false);// 循环播放
			mPlayer.prepare();
			mPlayer.start();
			
			mPlayer.setOnCompletionListener(new OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mp) {
                	mPlayer.reset();
                	mPlayer.release();
                }
            });
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	

	
}
